using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace LiveStock.dataAccess
{
    /// <summary>
    /// Data Access Layer class for Recommendations table
    /// </summary>
    class RecommendationsData
    {
        private RecommendationsData() { }

        public static Recommendations.RecommendationsDataTable RecommendationsGetByCompanyID(int companyID)
        {
            Recommendations.RecommendationsDataTable rdt = new Recommendations.RecommendationsDataTable();
            using (SqlCommand cmd = DBManager.GetCommand("RecommendationsGetByCompanyID"))
            {
                cmd.Parameters.AddWithValue("CompanyID", companyID);
                DBManager.FillDataTable(rdt, cmd);
            }
            return rdt;
        }

        public static int RecommendationInsert(Recommendations.RecommendationsRow rr)
        {
            int id = 0;
            using (SqlCommand cmd = DBManager.GetCommand("RecommendationInsert"))
            {
                cmd.Parameters.AddWithValue("CompanyID", rr.CompanyID);
                cmd.Parameters.AddWithValue("RatingTypeID", rr.RatingTypeID);
                cmd.Parameters.AddWithValue("RecommendationDate", rr.RecommendationDate);
                cmd.Parameters.AddWithValue("Rating", rr.Rating);
                cmd.Parameters.AddWithValue("Price", rr.Price);
                id = Convert.ToInt32(DBManager.ExecuteScalar(cmd));
            }
            return id;
        }

        public static Recommendations.RecommendationsDataTable RecommendationGetByID(int recommendationID)
        {
            Recommendations.RecommendationsDataTable rdt = new Recommendations.RecommendationsDataTable();
            using (SqlCommand cmd = DBManager.GetCommand("RecommendationGetByID"))
            {
                cmd.Parameters.AddWithValue("RecommendationID", recommendationID);
                DBManager.FillDataTable(rdt, cmd);
            }
            return rdt;
        }

        public static int RecommendationDeleteByID(int recommendationID)
        {
            int ar = 0;
            using (SqlCommand cmd = DBManager.GetCommand("RecommendationDeleteByID"))
            {
                cmd.Parameters.AddWithValue("RecommendationID", recommendationID);
                ar = DBManager.ExecuteNonQuery(cmd);
            }
            return ar;
        }

        public static int RecommendationUpdate(Recommendations.RecommendationsRow rr)
        {
            int ar = 0;
            using (SqlCommand cmd = DBManager.GetCommand("RecommendationUpdate"))
            {
                cmd.Parameters.AddWithValue("RecommendationID", rr.RecommendationID);
                cmd.Parameters.AddWithValue("CompanyID", rr.CompanyID);
                cmd.Parameters.AddWithValue("RatingTypeID", rr.RatingTypeID);
                cmd.Parameters.AddWithValue("RecommendationDate", rr.RecommendationDate);
                cmd.Parameters.AddWithValue("Rating", rr.Rating);
                cmd.Parameters.AddWithValue("Price", rr.Price);
                ar = DBManager.ExecuteNonQuery(cmd);
            }
            return ar;
        }

        public static Recommendations.RecommendationsDataTable RecommendationMostRecentGetByCompanySymbol(string symbol)
        {
            Recommendations.RecommendationsDataTable rdt = new Recommendations.RecommendationsDataTable();
            using (SqlCommand cmd = DBManager.GetCommand("RecommendationMostRecentGetByCompanySymbol"))
            {
                cmd.Parameters.AddWithValue("Symbol", symbol);
                DBManager.FillDataTable(rdt, cmd);
            }
            return rdt;
        }
    }
}
